/**
 * Created by EEO on 2017/8/12.
 */
require(['init'], function () {
    function Agencyinformation() {
        $("input").focus(function () {
            $('#J_enroll_submit').attr("disabled", false);
        });
        $.ajax({
            url: '/api/system/mailconfig',
            type: 'get',
            success: function (data) {
                $('#J_enroll_submit').attr("disabled", "disabled");
                $('[name=mail_host]').val(data.data.mail_host);
                $('[name=mail_port]').val(data.data.mail_port);
                $('[name=mail_uername]').val(data.data.mail_uername);
                $('[name=mail_password]').val(data.data.mail_password);
                $('[name=mail_from_address]').val(data.data.mail_from_address);
                $('[name=checkteachertime]').val(data.data.checkteachertime);
                $('[name=mail_from_name]').val(data.data.mail_from_name);
                if(data.data.mail_smtpsecure=='ssl'){
                    $('[name=checkteachertime]').click();
                }
            }
        })
        //点击保存
        $("#J_enroll_submit").on("click", function () {
            if (FormCheck.childrenInputCheck($('#J_enroll_wrap'))) {
                var mail_host = $('[name=mail_host]').val();
                var mail_port = $('[name=mail_port]').val();
                var mail_uername = $('[name=mail_uername]').val();
                var mail_password = $('[name=mail_password]').val();
                var mail_from_address = $('[name=mail_from_address]').val();
                var mail_smtpsecure = $('[name=checkteachertime]').prop('checked') ? 'ssl': '';
                var mail_from_name = $('[name=mail_from_name]').val();
                var arr = {
                    "mail_host": mail_host,
                    "mail_port": mail_port,
                    "mail_uername": mail_uername,
                    "mail_password": mail_password,
                    "mail_from_address": mail_from_address,
                    "mail_from_name": mail_from_name,
                    "mail_smtpsecure": mail_smtpsecure
                }
                var popUpBox = new PopUpBox({
                    type: 'dom',
                    style: 'default contentScroll',
                    submitBtnType: 'confirm',
                    titleText:i18next.t('popupbox.warmprompt'),//温馨提示
                    show: true,
                    content: '<div style="margin-left:27px;margin-top:34px;">'+i18next.t('popupbox.oksave')+'</div>',//确定要保存吗?
                    callback: {
                        yes: function (e) {
                            ajaxMethod({
                                url: '/api/system/mailconfig',
                                data: arr,
                                type: 'post',
                                success: function (data,status) {
                                    if(status.code!=0){
                                        var popUpBox = new PopUpBox({
                                            type: 'dom',
                                            style: 'default contentScroll',
                                            submitBtnType: 'alert',
                                            titleText:i18next.t('popupbox.warmprompt'),//温馨提示
                                            show: true,
                                            content: '<div style="margin-left:27px;margin-top:34px;">'+status.message+'!</div>',
                                            callback: {
                                                yes: function (e) {
                                                }
                                            },
                                            position: {
                                                width: 448,
                                                height: 226
                                            }
                                        })
                                        $(".submitBtnBox").find('.btn').css('margin-left','283px')
                                    }else{
                                        var popUpBox = new PopUpBox({
                                            type: 'dom',
                                            style: 'default contentScroll',
                                            submitBtnType: 'alert',
                                            titleText:i18next.t('popupbox.warmprompt'),//温馨提示
                                            show: true,
                                            content: '<div style="margin-left:27px;margin-top:34px;">'+i18next.t('info.savesuccessfully')+'!</div>',
                                            callback: {
                                                yes: function (e) {
                                                    window.location.reload();
                                                }
                                            },
                                            position: {
                                                width: 448,
                                                height: 226
                                            }
                                        })
                                        $(".submitBtnBox").find('.btn').css('margin-left','283px')
                                    }
                                }
                            })
                        }
                    },
                    position: {
                        width: 448,
                        height: 226
                    }
                })
            }


        })
    }

    Agencyinformation();


})
